import { createVNode as _createVNode, resolveDirective as _resolveDirective } from "vue";
import PropTypes from './vue-types';
import { defineComponent, nextTick, onBeforeMount, onBeforeUnmount, onUpdated, Teleport } from 'vue';
export default defineComponent({
  name: 'Portal',
  inheritAttrs: false,
  props: {
    getContainer: PropTypes.func.isRequired,
    didUpdate: PropTypes.func
  },
  setup: function setup(props, _ref) {
    var slots = _ref.slots;
    var isSSR = true; // getContainer 不会改变，不用响应式

    var container;
    onBeforeMount(function () {
      isSSR = false;
      container = props.getContainer();
    });
    onUpdated(function () {
      nextTick(function () {
        var _a;

        (_a = props.didUpdate) === null || _a === void 0 ? void 0 : _a.call(props, props);
      });
    });
    onBeforeUnmount(function () {
      if (container && container.parentNode) {
        container.parentNode.removeChild(container);
      }
    });
    return function () {
      var _a;

      if (isSSR) {
        return (_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots);
      }

      return container ? _createVNode(Teleport, {
        "to": container
      }, slots) : null;
    };
  }
});